import irrlicht;
import std.stdio;

void main()
{
	E_DRIVER_TYPE driverType;
	writeln("Please select the driver you want for this example:\n"~
			" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"~
			" (d) Software Renderer\n (e) Burning's Software Renderer\n"~
			" (f) NullDevice\n (otherKey) exit\n\n");
			
	switch(readln()[0])
	{
		case 'a': driverType = E_DRIVER_TYPE.EDT_DIRECT3D9;break;
		case 'b': driverType = E_DRIVER_TYPE.EDT_DIRECT3D8;break;
		case 'c': driverType = E_DRIVER_TYPE.EDT_OPENGL;break;
		case 'd': driverType = E_DRIVER_TYPE.EDT_SOFTWARE;break;
		case 'e': driverType = E_DRIVER_TYPE.EDT_BURNINGSVIDEO;break;
		case 'f': driverType = E_DRIVER_TYPE.EDT_NULL;break;
		default: assert(0, "No driver selected.");
	}
	
	IrrlichtDevice device = createDevice(driverType, new UintDimension2D(640, 480), 16, false, false, false, null);
	assert(device, "Unable to create device.");
	
	//scope(exit)clear(device);  ??
	
	IVideoDriver driver = device.getVideoDriver();
	ISceneManager smgr = device.getSceneManager();
	
	device.getFileSystem().addZipFileArchive("media/map-20kdm2.pk3");
	
	IAnimatedMesh mesh = smgr.getMesh("20kdm2.bsp");
	ISceneNode node;
	
	if(mesh)
		node = smgr.addOctreeSceneNode(mesh.getMesh(0), null, -1, 1024);
		
	if(node)
		node.setPosition(new FloatVector3D(-1300, -144, -1249));
		
	smgr.addCameraSceneNodeFPS();
	
	device.getCursorControl().setVisible(false);
	
	int lastFPS = -1;
	
	while(device.run())
	{
		if(device.isWindowActive())
		{
			driver.beginScene(true,true,new SColor(255, 200, 200, 200));
			smgr.drawAll();
			driver.endScene();
			
			int fps = driver.getFPS();
			if(lastFPS != fps)
			{
				wstring str = "Irrlicht Engine with D via SWIG - Quake 3 Map example[";
				str ~= std.conv.to!wstring(driver.getName());
				str ~= "] FPS:";
				str ~= std.conv.to!wstring(fps);
				
				device.setWindowCaption(str);
				lastFPS = fps;
			}
		}
		else
			device.yield();
	}
}